package com.czxy.Demo24;

import java.io.FileInputStream;
import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.Properties;

public class Test {
    public static void main(String[] args) throws ClassNotFoundException, IllegalAccessException, InstantiationException, NoSuchMethodException, IOException, InvocationTargetException {
        Properties pro = new Properties();
        FileInputStream fileInputStream = new FileInputStream("data.properties");
        pro.load(fileInputStream);
        fileInputStream.close();

        // 反射创建 user 对象
        Class<?> aClass = Class.forName("com.czxy.Demo24.User");
        Object o = aClass.newInstance();
        // 调用 set 方法
        Method setUid = aClass.getMethod("setUid", String.class);
        setUid.invoke(o , pro.getProperty("uid"));
        // 调用 set 方法
        Method setUsername = aClass.getMethod("setUsername", String.class);
        setUsername.invoke(o , pro.getProperty("username"));
        // 调用 set 方法
        Method setPassword = aClass.getMethod("setPassword", String.class);
        setPassword.invoke(o , pro.getProperty("password"));

        System.out.println(o);
    }
}
